package com.roger.tool.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;

public class SharedUtil {

	private static int MODE_MULTI_PROCESS = 4;

	public static void setListener(Context context, String name, OnSharedPreferenceChangeListener listener) {
		SharedPreferences sharedata = context.getSharedPreferences(name, MODE_MULTI_PROCESS);
		sharedata.registerOnSharedPreferenceChangeListener(listener);
	}

	public static void clear(Context context, String name) {
		SharedPreferences.Editor sharedata = context.getSharedPreferences(name, MODE_MULTI_PROCESS).edit();
		sharedata.clear();
		sharedata.commit();
	}

	public static boolean editString(Context context, String name, String key, String value) {
		SharedPreferences.Editor sharedata = context.getSharedPreferences(name, MODE_MULTI_PROCESS).edit();
		sharedata.putString(key, value);
		return sharedata.commit();
	}

	public static String getString(Context context, String name, String key, String defaultValue) {
		SharedPreferences sharedata = context.getSharedPreferences(name, MODE_MULTI_PROCESS);
		String data = sharedata.getString(key, defaultValue);
		return data;
	}

	public static boolean editBoolean(Context context, String name, String key, boolean value) {
		SharedPreferences.Editor sharedata = context.getSharedPreferences(name, MODE_MULTI_PROCESS).edit();
		sharedata.putBoolean(key, value);
		return sharedata.commit();
	}

	public static boolean getBoolean(Context context, String name, String key, boolean defaultValue) {
		SharedPreferences sharedata = context.getSharedPreferences(name, MODE_MULTI_PROCESS);
		boolean data = sharedata.getBoolean(key, defaultValue);
		return data;
	}

	public static boolean editInt(Context context, String name, String key, int value) {
		SharedPreferences.Editor sharedata = context.getSharedPreferences(name, MODE_MULTI_PROCESS).edit();
		sharedata.putInt(key, value);
		return sharedata.commit();
	}

	public static int getInt(Context context, String name, String key, int defaultValue) {
		SharedPreferences sharedata = context.getSharedPreferences(name, MODE_MULTI_PROCESS);
		int data = sharedata.getInt(key, defaultValue);
		return data;
	}

	public static boolean editLong(Context context, String name, String key, long value) {
		SharedPreferences.Editor sharedata = context.getSharedPreferences(name, MODE_MULTI_PROCESS).edit();
		sharedata.putLong(key, value);
		return sharedata.commit();
	}

	public static long getLong(Context context, String name, String key, long defaultValue) {
		SharedPreferences sharedata = context.getSharedPreferences(name, MODE_MULTI_PROCESS);
		long data = sharedata.getLong(key, defaultValue);
		return data;
	}

	public static boolean editFloat(Context context, String name, String key, float value) {
		SharedPreferences.Editor sharedata = context.getSharedPreferences(name, MODE_MULTI_PROCESS).edit();
		sharedata.putFloat(key, value);
		return sharedata.commit();
	}

	public static float getFloat(Context context, String name, String key, float defaultValue) {
		SharedPreferences sharedata = context.getSharedPreferences(name, MODE_MULTI_PROCESS);
		float data = sharedata.getFloat(key, defaultValue);
		return data;
	}

}
